﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATM.Entities;

namespace ATM.DataAccess
{
    /// <summary>
    /// Truy xuat du lieu lien quan den Account
    /// Cung cap cac method:
    /// - GetAccount()
    /// - CheckAccountExist()
    /// - GetBalance()
    /// - WithdrawMoney()
    /// </summary>
    public class AccountDal
    {
        public Account GetAccount(int accountId)
        {
            return VirtualData.AccountList.SingleOrDefault(t => t.AccountId == accountId);
        }

        //Kiem tra Account co ton tai?
        public bool CheckAccountExist(int accountId)
        {
            Account ac = VirtualData.AccountList.SingleOrDefault(t => t.AccountId == accountId);
            if (ac == null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        //GetBalance
        public double GetBalance(int accountId)
        {
            return VirtualData.AccountList.SingleOrDefault(t => t.AccountId == accountId).Balance;
        }

        //Withdraw Money
        public bool WithdrawMoney(int accountId, double amount)
        {
            try
            {
                Account acc = GetAccount(accountId);
                acc.Balance -= amount;
                return true;
            }
            catch (Exception ex)
            {
                
                throw;
            }
        }
    }
}
